<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
<title>库存盘点管理</title>
<meta name="decorator" content="default" />
<style type="text/css">
	table thead tr {
		background: rgb(190, 190, 194);
	}
</style>
<script type="text/javascript">
	$(document).ready(function() {
		$("#contentTable tbody tr").click(function() {
			$("#contentTable tbody tr").removeClass(
					"select_active");
			$(this).addClass("select_active");
			var checkTd = $("#checkbox-" + this.id);
			checkTd.attr("checked",!checkTd.attr("checked"));
			var isAll = true;
			 $('.sysProduct').each(function(){
				 if(!this.checked){
					 isAll = false;
				 }
			 });
			 $("#selectAll").attr("checked",isAll);
		});
		$("#contentTable thead tr").click(function() {
			 $("#selectAll").click();
		});
		$("#inputForm").validate({
			submitHandler : function(form) {
				loading('正在提交，请稍等...');
				form.submit();
			},
			errorContainer : "#messageBox",
			errorPlacement : function(error, element) {
				$("#messageBox").text("输入有误，请先更正。");
				if (element.is(":checkbox")
						|| element.is(":radio")) {
					error.appendTo(element.parent()
							.parent());
				} else {
					error.insertAfter(element);
				}
			}
		});
		$("#addSelect").click(function() {
			var selectIds = "";
			$('.sysProduct').each(function(){
				 if(this.checked){
					 selectIds += this.value + ",";
				 }
			});
			if (!selectIds) {
				showTip("未选择产品,请选择");
				return;
			}
			if (selectIds) {
				var url = "${ctx}/inventory/storeInventoryCheck/saveProduct?productIds="
						+ selectIds;
				window.location.href = url;
			}
		});
		$("#selectAll").click(function(e){
			 $('.sysProduct').attr("checked",this.checked);
			 e.stopPropagation();
		});
		$('.sysProduct').click(function(e){
			var isAll = true;
			 $('.sysProduct').each(function(){
				 if(!this.checked){
					 isAll = false;
				 }
			 });
			 $("#selectAll").attr("checked",isAll);
			 e.stopPropagation();
		});
	});
</script>
</head>
<body>
<div class="form-input">
	<div class="icon-buttons">
		<a id="btnBack" data-role="button"  data-icon="back" data-iconpos="notext"  data-inline="true" href="${ctx}/inventory/storeInventoryCheck/detailList">返回</a>
		<input id="addSelect" type="button"  data-icon="check" data-iconpos="notext"  data-inline="true" value="添加选中产品">
	</div>
	<label style="text-align: center;"><h2>产品选择</h2></label>
	<table id="contentTable" data-role="table" class="ui-responsive table-stroke">
		<thead>
			<tr>
				<th>
					<c:if test="${not empty systemProductList}">
						<input type="checkbox" id="selectAll" data-inline="true" checked value="all"/>
					</c:if>
				</th>
				<th>产品分类</th>
				<th>产品名称</th>
				<th>规格</th>
				<th>零售价</th>
				<th>数量</th>
			</tr>
		</thead>
		<tbody>
			<c:if test="${empty systemProductList}">
				<tr>
					<td colspan="6" style="text-align: center;">库存中的产品已经全部被选择</td>
				</tr>
			</c:if>
			<c:if test="${not empty systemProductList}">
				<c:forEach items="${systemProductList}" var="sysProduct">
					<tr id="${sysProduct.id}">
						<td><input type="checkbox" checked id="checkbox-${sysProduct.id}" class="sysProduct" value="${sysProduct.id}"/></td>
						<td>${sysProduct.product.productCategory.name}</td>
						<td>${sysProduct.product.name}</td>
						<td>${sysProduct.product.spec}</td>
						<td>${sysProduct.product.retail_price}</td>
						<td>${sysProduct.amount}</td>
					</tr>
				</c:forEach>
			</c:if>
		</tbody>
	</table>
	</div>
</body>
</html>
